package com.k3cloud.rpc.http.service;

import com.alibaba.fastjson.JSONObject;
import com.hustcad.plm.pdm.flowbusiness.model.entity.FlowObject;
import com.hustcad.plm.pdm.partbom.vo.PartDetailsVO;
import com.k3cloud.base.dto.HttpClientTokenDTO;
import com.k3cloud.base.dto.entity.ExecutionTypeDO;
import org.apache.http.client.methods.HttpRequestBase;

import java.util.Map;

public interface RemoteProcedureCallService {
    /**
     * 授权结构,二开需要实现此方法
     * 返回的Object结构将传送到getToken方法中
     * @return
     */
    public <T> T  getAuthorizationEntity();
    /**
     * 获取token
     * @param obj
     * @return
     */
    public HttpClientTokenDTO getToken(Object authorizationEntity, Object obj);

    /**
     * 设置参数
     * @param token
     * @param partDetails
     */
    public void setParameter(HttpClientTokenDTO token, PartDetailsVO partDetails, ExecutionTypeDO executionTypeDO, FlowObject flowObject,Object parameter);
    /**
     * 把token写入httpclient
     * @param token
     * @param httpRequestBase
     */
    public void changeHttpClientHeaders(HttpClientTokenDTO token, HttpRequestBase httpRequestBase, ExecutionTypeDO executionTypeDO);

    /**
     * 判断是否需要重新获取授权
     * @param obj
     * @return
     */
    public boolean needReGetToken(Object obj, ExecutionTypeDO executionTypeDO);


    /**
     * 发送前，可修改数据结构
     * @param token
     */
    public Map<String,Object> sendBefore(HttpClientTokenDTO token, Map<String, Object> outMap, ExecutionTypeDO executionTypeDO, FlowObject flowObject,Object parameter);

    /**
     * 主请求发送后
     * @return
     */
    public JSONObject sendAfter(JSONObject result, ExecutionTypeDO executionTypeDO, FlowObject flowObject, Object parameter);
    /**
     * 重构返回结果
     * @return
     */
    public JSONObject reconstructResult(JSONObject result, ExecutionTypeDO executionTypeDO);

}
